package com.kdgc.power.business.controller;

import com.kdgc.power.business.entity.SysMenu;
import com.kdgc.power.business.service.SysMenuService;
import com.kdgc.power.fw.bean.JsonMsg;
import com.kdgc.power.fw.bean.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("SysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;


    @RequestMapping("page")
    public Object page(HttpServletRequest request, int page, int rows) {
        return sysMenuService.getPage("sysCMenu.select", null, page, rows);
    }


    @RequestMapping("findById")
    public Map<String ,Object> findById(Integer id) {
        return sysMenuService.getMapEntity(id);
    }


    @RequestMapping("save")
    public JsonMsg save(SysMenu sysMenu) {
        boolean success = sysMenuService.saveWithChildren(sysMenu);
        return new JsonMsg(success);
    }


    @RequestMapping("deleteById")
    public JsonMsg deleteById(Integer id) {
        int rows = sysMenuService.removeById(id);
        return new JsonMsg(rows == 1);
    }

    @RequestMapping("getTree")
    public List<TreeNode> getTree(String flag) {

        return sysMenuService.getTree(flag);
    }
}